{include file="admin@public/header"/}

<style>
    .backup-status{margin: 10px 0 20px;}
    .backup-warning {
      position: relative;
      padding-left: 20px;
      margin-top: 5px;
      font-size: 13px;
      color: #e2a758;
    }
    .warning-icon {
      display: inline-block;
      position: absolute;
      top: 2px;
      left: 0;
      width: 16px;
      height: 16px;
      background: url('/css/default/img/spr_icons.png') -32px 0 no-repeat;
    }
    .mod-toolbar-top {
        padding: 0 18px 0px 0;
    }
    .chk_blue {
        position: relative;
        font-size: 12px;
        background-position-y: center;
    }
    .chk_blue input {
        display: inline-block;
        position: absolute;
        width: 16px;
        height: 16px;
        cursor: pointer;
        left: 0;
        top: 1px;
        opacity: 0;
    }
    .chk_blue label {
        margin-left: 10px;
    }
    #start-backup {
        display: none;
    }
</style>

<div class="wrapper setting-wrap">
    <div class="mod-toolbar-top cf">
        <a class="ui-btn ui-btn-sp fl mrb" id="start-backup" herf="#">开始备份</a>
        <a class="ui-btn ui-btn-sp fl mrb" id="start-backup-new" herf="#">开始备份</a>
        <!--<a class="ui-btn fl" id="auto-backup" herf="#">自动备份</a>-->
        <!--<a herf="#" class="ui-btn fl local-recover" id="localRecover">上传本地备份</a>-->
        <form id="form1" style="display:none;">
            <input type="file" id="scsql" accept=".sql">   
        </form>
        <a herf="#" class="ui-btn fl local-recover mrb" onclick="sc()" id="localRecoverNew">上传本地备份</a>
        <a herf="javascript:void(0);" class="ui-btn fl" onclick="alldel()" id="multipleDelete">批量删除</a>
    </div>
    <p class="backup-warning">
        <i class="warning-icon"></i>
        系统仅支持最多同时保留5个备份文件，备份文件已加密，下载后不能直接打开，可上传并恢复到本系统查看
    </p>
    <div class="grid-wrap">
    	<div id="backup-status" class="backup-status">
            <table id="grid"></table>
        </div>
    </div> 
</div>

<script>
    $("#start-backup-new").click(function(){
        layer.confirm('为保证备份数据的完整性，请确保账套里的其他用户已经退出系统。确定执行备份？',{icon: 3, title:'开始备份'},function(){
            var bf=1;
            layer.closeAll();
            layer.load(1);
            $.ajax({
                type:"post",
                url:"bf",
                datatype:'json',
                data:{
                    bf:bf,
                },
                success:function(data){
                    if (data.code==1) {
                        layer.closeAll();
                        layer.msg(data.msg,{icon:1,time:1000});
                        $("#grid").jqGrid('setGridParam').trigger("reloadGrid"); //重新载入
                    }else{
                        layer.closeAll();
                        layer.msg(data.msg,{icon:2,time:1000});
                    }
                    
                },
                error:function(da){
                    layer.msg('请求失败');
                }
            })

        })

    })
    $(document).ready(function () {
        $("#grid").jqGrid({
			url: '/system/backup/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: $(window).height()*0.8,//高度，表格高度。可为数值、百分比或'auto'
            colNames:['操作', '备份名称', '时间', '文件大小'],
            colModel:[
                { name: 'id', width: 90 , label:'操作', formatter:actions},
                { name: 'name', width: 400 , label:'备份名称'},
                { name: 'time', width: 80 , label:'时间'},
                { name: 'cont', width: 80 , label:'文件大小',formatter:conn},
            ],
            altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
            viewrecords: !0,
            multiselect: true,//自带多选
			cmTemplate: {
				sortable: !1,
				title: !1
			},
            loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			}
        });
    });

    function conn(cellvalue, options, rowObject) {
        return '<p>'+cellvalue+'条'+'</p>';
    }
    function actions(cellvalue, options, rowObject) {
        console.log(rowObject.lj);
        var xz = rowObject.name;
        var jz = "/public/data/"+xz;
        console.log(jz);
		return '<p class="operate-wrap operating"><a class="btn-recover ui-icon ui-icon-copy" href="#" onclick="hf(' + cellvalue + ')" title="恢复">恢复</a><a class="btn-download ui-icon ui-icon-arrowthickstop-1-s" href="' + jz + '" target="_blank" title="下载">下载</a><a class="btn-del ui-icon ui-icon-trash" href="#"onclick="del(' + cellvalue + ')" title="删除">删除</a></p>';
	}
    function hf(id){
        layer.load(1);
        $.ajax({
            type:"post",
            url:"hf",
            datatype:'json',
            data:{
                id:id,
            },
            success:function(data){
                if (data.code==1) {
                        layer.closeAll();
                        layer.msg(data.msg,{icon:1,time:1000});
                        $("#grid").jqGrid('setGridParam').trigger("reloadGrid"); //重新载入
                    }else{
                        layer.closeAll();
                        layer.msg(data.msg,{icon:2,time:1000});
                    }
            },
            error:function(da){
                layer.msg('请求失败');
            }
        })
    }
    function del(id){
        layer.load(1);
        $.ajax({
            type:"post",
            url:"del",
            datatype:'json',
            data:{
                alld:'1',
                del:id,
            },
            success:function(data){
                if (data.code==1) {
                    layer.closeAll();
                    layer.msg(data.msg,{icon:1,time:1000});
                    $("#grid").jqGrid('setGridParam').trigger("reloadGrid"); //重新载入
                }else{
                    layer.closeAll();
                    layer.msg(data.msg,{icon:2,time:1000});
                }
                
            },
            error:function(da){
                layer.msg('请求失败');
            }
        })
    }
    function alldel(){
        var ids = $("#grid").jqGrid('getGridParam','selarrrow');
        $.ajax({
            type:"post",
            url:"del",
            datatype:'json',
            data:{
                del:ids,
            },
            success:function(data){
                if (data.code==1) {
                    layer.closeAll();
                    layer.msg(data.msg,{icon:1,time:1000});
                    $("#grid").jqGrid('setGridParam').trigger("reloadGrid"); //重新载入
                }else{
                    layer.closeAll();
                    layer.msg(data.msg,{icon:2,time:1000});
                }
                
            },
            error:function(da){
                layer.msg('请求失败');
            }
        })
    }
    //上传本地文件
    function sc(){
        layer.open({
            type: 1, 
            title: '上传本地文件',
            content: $("#form1"),
            area: ['600px', '500px'],
            btn: ['确定', '取消']
              ,yes: function(index, layero){
                var file =$("#scsql")[0].files[0];//获取文件
                var fromdata = new FormData();//实例化 FormData 用于ajax模拟表单提交
                fromdata.append('file', file);//上传表单
                $.ajax({
                type:"post",
                url:"sc",
                datatype:"json",
                data:fromdata,
                processData: false,
                contentType: false,
                    success:function(data){
                        if (data.code==1) {
                           layer.closeAll();
                            layer.msg(data.msg,{icon:1,time:1000});
                            $("#grid").jqGrid('setGridParam').trigger("reloadGrid"); //重新载入
                        }else{
                            layer.msg(data.msg);
                        }
                        },
                    error:function(da){
                        alert('请求失败');
                    },
                });
              }
              ,btn2: function(index, layero){
              }
        });
    }
</script>


{include file="admin@public/footer"/}